<template>
	<view class="u-rela">
		<u-swiper img-mode="scaleToFill" name="image_text" :list="list1" height="400" radius="0"></u-swiper>
		<view class="module-content">
			<view class="userinfo u-f-item u-f-jsb u-p-30" v-if="!isLogin" @click="toLogin">
				<view class="u-f-item">
					<u-avatar size="80"></u-avatar>
					<view class="u-f1 u-p-l-20 u-f-item">
						<view class="u-font-36">去登录</view>
					</view>
				</view>

			</view>
			<view style="margin-bottom: 30rpx;" class="userinfo u-p-30  " @tap="toAll()" v-if="isLogin"
				>
				<view class="u-f1 u-p-l-20 u-font-36 u-f-item u-f-jsb">
					{{myInfo.name}}
					<view class="block u-f-item u-font-32 u-f-justify" style="color: #999;">
										查看答题记录 <u-icon name="arrow-right" color="#999"></u-icon>
									</view>
				</view>

			</view>
			<!-- <view class="module-block" v-if="isLogin">
				<view class="block" style="margin-bottom: 40rpx;">
					<view class="item">
						<view class="count">{{userinfo.total_question_num}}</view>
						<view class="title">答题数量</view>
					</view>
					<view class="item">
						<view class="count">{{userinfo.correct_ratio}}</view>
						<view class="title">正确率（%）</view>
					</view>
				</view>
				<view class="block">
					<view class="item">
						<view class="count">{{userinfo.total_correct}}</view>
						<view class="title">正确数量</view>
					</view>
					<view class="item">
						<view class="count">{{userinfo.total_wrong}}</view>
						<view class="title">错误数量</view>
					</view>
				</view>
				<view class="block" @tap="toAll()" style="color: #999;justify-content: center;padding-top: 30rpx;">
					查看答题记录 <u-icon name="arrow-right" color="#999"></u-icon>
				</view>
			</view> -->
		</view>

		<button class="u-reset-button" @tap="toList()" v-if="isLogin">去答题</button>
		<button class="u-reset-button" @tap="toAll1" v-if="isLogin">模拟练习</button>
		<!-- <view class="block" v-if="isLogin" @tap="toAll1"
			style="color: #999;justify-content: center;padding-top: 20rpx;text-align: center;">
			模拟练习
			<u-icon name="arrow-right" color="#999"></u-icon>
		</view> -->
		<view class="block" v-if="isLogin" @tap="goOut"
			style="color: #999;justify-content: center;margin-top: 40rpx;text-align: center;">
			退出登录
		</view>
		<!-- #ifdef MP-WEIXIN -->
		<ws-wx-privacy id="privacy-popup"></ws-wx-privacy>
		<!-- #endif -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				curIndex: 0,
				list1: [],
				isLogin: false,
				myInfo: {},
				userinfo: {},
				dataList: []
			}
		},
		onLoad() {

		},
		onShow() {
			this.curIndex = 0
			this.dataList = []
			this.userinfo = {}
			if (this.$db.get('userToken')) {
				this.getUserInfo()

				this.myInfo = JSON.parse(this.$db.get('userInfo'))
			} else {
				this.isLogin = false;
			}

			//#ifdef MP-WEIXIN
			wx.requirePrivacyAuthorize({
				success: () => {
					console.log('点击同意');
				},
				fail: () => {
					console.log('点击拒绝');

				},
				complete: () => {
					console.log('用户已点击');
				}
			})
			//#endif
			this.$api.bannerList({}, res => {
				if (res.code == 1) {
					this.list1 = res.data;
				}
			})
		},
		methods: {
			goOut() {

				let _this = this;
				uni.showModal({
					title: '提示',
					content: '确认退出登录吗？',
					success(r) {
						if (r.confirm) {
							_this.$api.logout({}, res => {
								if (res.code == 1) {
									_this.$common.errorToShow('退出成功', () => {

										_this.$db.clear()
										uni.navigateTo({
											url: '/pages/login/index'
										})
									})
								} else {
									_this.$common.errorToShow(res.msg)
								}
							})
						}
					}
				})

			},
			toLogin() {
				uni.navigateTo({
					url: '/pages/login/index'
				})
			},
			toList() {

				this.$api.checkAnswerNum({
					methodType: 'get'
				}, res => {
					if (res.code == 1 && res.data) {
						uni.navigateTo({
							url: '/pages/index/list'
						})
					} else {
						this.$common.errorToShow('暂无答题次数')

					}
				})
			},
			toAll() {
				uni.navigateTo({
					url: '/pages/index/all'
				})
			},
			toAll1() {
				uni.navigateTo({
					url: '/pages/index/list1'
				})
			},
			getUserInfo() {

				this.$api.userInfo({}, res => {
					if (res.code == 1) {
						this.isLogin = true;
						this.userinfo = res.data;
					}
				})
			},
		}
	}
</script>

<style>
	.module-content {
		padding: 30rpx;
	}

	.userinfo {
		box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.25);
		background: #fff;
		border-radius: 20rpx;
	}

	.hd {
		background: rgba(210, 210, 255, 0.8);
		width: 88rpx;
		height: 88rpx;
		border-radius: 50%;
	}
</style>

<style lang="scss">
	.u-reset-button {

		font-size:32rpx;
		background: linear-gradient(90deg, #3D7EEA 8.12%, #02B0F1 95.73%);
		color: #fff;
		height: 90rpx;
		width: 500rpx;
		margin: 0 auto;
		line-height: 90rpx;
		border-radius: 50rpx;
		margin-top: 20rpx;
	}

	.module-block {
		box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.25);
		background: #fff;
		border-radius: 20rpx;
		padding: 60rpx;

		.block {
			display: flex;
			align-items: center;
			justify-content: space-between;

		}

		.item {
			width: 50%;
			text-align: center;
		}

		.title {
			font-size: 26rpx;
		}

		.count {
			font-size: 50rpx;
			font-weight: bold;
			margin-bottom: 6rpx;

		}
	}
</style>